import network
import json
import server




class WIFI:
    @staticmethod
    def GETWIFICONFIG():

        with open('WIFI_CONFIG.json', 'r') as f:
            value = f.read()
            ssid = json.loads(value)['ssid']
            password = json.loads(value)['password']
            return ssid, password

    def __init__(self):
        self.ssid, self.password = self.GETWIFICONFIG()
        self.WIFICONNECT()

    def WIFICONNECT(self):
        self.wlan = network.WLAN(network.STA_IF)
        self.wlan.active(True)
        self.wlan.connect(self.ssid, self.password)
        # 静态ip
        # wlan.ifconfig(('192.168.2.101', '255.255.255.0','192.168.2.1', '192.168.2.1'))
        if self.wlan.isconnected():
            print(self.wlan.ifconfig())
            print("wifi connect successful")
        else:
            print("wifi connect failed")








